//
// Created by Zhang on 2022/4/8.
//
#include <iostream>
#include <math.h>
#include <string>

// chapter 3 ppt extra 2
class CPoint {
private:
    float x, y;
public:
    CPoint(float i, float j) : x(i), y(j) {};

    float X() const {
        return x;
    }

    float Y() const {
        return y;
    }
};


class CLine : public CPoint {
private:
    CPoint b;
public:
    CLine(CPoint i, CPoint j) : CPoint(i.X(), i.Y()), b(j) {};

    float distance() const;

    CPoint A() {
        return CPoint(X(), Y());
    }

    CPoint B() {
        return b;
    }

};

float CLine::distance() const {
    float d = sqrt((X() - b.X()) * (X() - b.X()) + (Y() - b.Y()) * (Y() - b.Y()));
    return d;
}

class CReact : public CLine {
    CLine b;
public:
    CReact(CLine i, CLine j) : CLine(i.A(), i.B()), b(j) {};

    float area();

    float perimeter();
};

float CReact::area() {
    float x = distance();
    float y = CLine(A(), b.A()).distance();
    return x * y;
}

float CReact::perimeter() {
    float x = distance();
    float y = CLine(A(), b.A()).distance();
    return 2 * x + 2 * y;
}

// chapter 3 ppt extra 3
class CStrOne {
    std::string s;
public:
    CStrOne(std::string a) : s(a) {};

    void output() {
        std::cout << s << std::endl;
    }

protected:
    std::string S() {
        return s;
    }
};

class CStrTwo : public CStrOne {
    std::string ss;
public:
    CStrTwo(std::string a, std::string b) : CStrOne(a), ss(b) {};

    void output() {
        std::string x = S() + ss;
        std::cout << x << std::endl;
    }
};

// book q1
class circle {
    float r;
public:
    circle(float R) : r(R) {};

    void area() {
        std::cout << r * r * 3.1415926535 << std::endl;
    }
};

class table {
    std::string color;
    float height;
public:
    table(std::string Color, float Height) : color(Color), height(Height) {};

    void Color() {
        std::cout << color << std::endl;
    }

    void Height() {
        std::cout << height << std::endl;
    }

};

//book q2
class Animal {
public:
    int age;
};

class dog : public Animal {
public:
    void SetAge(int a) {
        age = a;
    }
};

class roundtable : public circle, public table {
public:
    roundtable(float r, std::string Color, float Height) : circle(r), table(Color, Height) {};
};

//book q3
class Rectangle {
    float Length, Width;
public:
    Rectangle(float l, float w) : Length(l), Width(w) {};

    float Area() {
        return Length * Width;
    }

    void Show() {
        std::cout << Length << std::endl;
        std::cout << Width << std::endl;

    }
};

class Cuboid : public Rectangle {
private:
    float High;
public:
    Cuboid(float a, float b, float c) : Rectangle(a, b), High(c) {};

    float Vol() {
        return Area() * High;
    }

    void Show() {
        Rectangle::Show();
        std::cout << High << std::endl;
        std::cout << Vol() << std::endl;
    }
};

//book q4
class vehicle {
    int MaxSpeed, Weight;
public:
    vehicle(int a, int b) : MaxSpeed(a), Weight(b) {};

    void run() {
        std::cout << "run!" << std::endl;
    };

    void stop() {
        std::cout << "stop!" << std::endl;
    };

    void show() {
        std::cout << MaxSpeed << Weight << std::endl;
    }
};

class bicycle : virtual public vehicle {
private:
    float Height;
public:
    bicycle(int a, int b, float c) : vehicle(a, b), Height(c) {};

};

class motorcar : virtual public vehicle {
private:
    int SeatNum;
public:
    motorcar(int a, int b, int c) : vehicle(a, b), SeatNum(c) {};
};

class motorcyclye : public motorcar, public bicycle {
public:
    motorcyclye(int a, int b, int c, float d) : vehicle(a, b), bicycle(0, 0, d), motorcar(0, 0, c) {};


};

int main() {
// chapter 3 ppt extra 2
    CPoint A(0, 0), B(1, 1), C(1, -1), D(2, 0);
    CLine L1(A, B), L2(C, D);
    CReact R(L1, L2);
    std::cout << L1.distance() << " " << L2.distance() << " " << R.perimeter() << " " << R.area() << std::endl;


// chapter 3 ppt extra 3
    CStrOne a("abc");
    a.output();
    CStrTwo b("abc", "cba");
    b.output();

// book q1
    roundtable book_q1(3, "blue", 0.5);
    book_q1.Height();
    book_q1.area();
    book_q1.Color();

    //book q2
    dog bq2;
    bq2.SetAge(3);
    //如果age是私有变量则无法访问

    //book q3
    Cuboid cub(10, 20, 30);
    cub.Show();

    //book q4
    motorcyclye q4(1, 2, 3, 0.5);
    q4.show();

    return 0;
}